package com.zatech.cgnci.project.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zatech.cgnci.project.base.utils.VerifyUtils;
import com.zatech.cgnci.project.entity.CgnciReinsuranceInfoDO;
import com.zatech.cgnci.project.service.CgnciReinsuranceInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 分入/分出 前端控制器
 * </p>
 *
 * @author Generator
 * @since 2024-12-18
 */
@RestController
@RequestMapping("/api/reinsurance-info")
@Api(produces = "application/json", tags = "合约分出api接口文档")
@RequiredArgsConstructor
public class CgnciReinsuranceInfoController {

    private final CgnciReinsuranceInfoService cgnciReinsuranceInfoService;

    @GetMapping("/deleteByIds")
    @Transactional(rollbackFor = Exception.class)
    @ApiOperation(value = "批量删除")
    public void deleteByIds(@RequestParam(value = "reinsuranceIds") @NotBlank(message = "reinsuranceIds cannot be null") String reinsuranceIds) {
        List<Long> idList = Arrays.stream(reinsuranceIds.split(",")).map(Long::valueOf).collect(Collectors.toList());
        idList.forEach(reinsuranceId -> {
            CgnciReinsuranceInfoDO reinsuranceInfoDO = cgnciReinsuranceInfoService.getOne(new LambdaQueryWrapper<CgnciReinsuranceInfoDO>()
                    .eq(CgnciReinsuranceInfoDO::getReinsuranceId, reinsuranceId));
            if (VerifyUtils.isNotEmpty(reinsuranceInfoDO)) {
                cgnciReinsuranceInfoService.removeById(reinsuranceInfoDO.getReinsuranceId());
            }
        });
    }

}

